"use strict";
{
    class List {
        constructor() {
            this.pos = 0; // 指针
            this.listSize = 0;
            this.dataStore = [];
        }
        get length() {
            return this.dataStore.length;
        }
        clear() {
            this.dataStore = [];
            this.pos = 0;
            this.listSize = 0;
        }
        toString() {
            return this.dataStore.map((item) => item).join('\n');
        }
        getElement() {
            return this.dataStore[this.pos];
        }
        insert(element) {
            this.dataStore.splice(this.pos, 0, element); // 数组插入
        }
        append(element) {
            //   this.dataStore.push(element);
            //   this.listSize++;
            this.dataStore[this.listSize++] = element;
        }
        remove(element) {
            let index = this.find(element);
            if (index === -1)
                return false;
            this.dataStore.splice(index, 1);
            return true;
        }
        front() {
            if (this.pos !== 0) {
                this.exchange(this.pos, 0);
            }
        }
        end() {
            if (this.pos !== this.listSize - 1) {
                this.exchange(this.pos, this.listSize - 1);
            }
        }
        prev() {
            if (this.pos > 0) {
                this.pos--;
            }
        }
        next() {
            if (this.pos < this.listSize) {
                this.pos++;
            }
        }
        currPos() {
            return this.pos;
        }
        moveTo(pos) {
            if (pos >= 0 && !(pos > this.listSize - 1)) {
                this.pos = pos;
            }
        }
        find(element) {
            return this.dataStore.indexOf(element);
        }
        exchange(index1, index2) {
            let temp = this.dataStore[index1];
            this.dataStore[index1] = this.dataStore[index2];
            this.dataStore[index2] = temp;
        }
    }
    let names = new List();
    names.append(111);
    //   names.append('xuexue');
    //   names.append('Jack');
    //   names.append('Henry');
    console.log(names.getElement()); // jimmy
    names.next();
    console.log(names.getElement()); // jimmy
    //   names.prev();
    //   console.log(names.getElement());
    names.clear();
    console.log(names.getElement());
}
